package com.xiyoukt.springboot;

import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;
import java.util.Date;

public class User {

    @Pattern(regexp = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$",
            message = "手机号不符合规范", groups = {Registry.class, Login.class})
    private String phone;

    @NotNull(groups = {Login.class})
    @Length(min = 6, max = 16, message = "密码长度在6-16位", groups = {Registry.class, Login.class})
    private String password;

    @Min(value = 10, message = "年龄太小，不能注册", groups = {Registry.class})
    @Max(value = 60, message = "年龄太大，不能注册", groups = {Registry.class})
    private Integer age;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Past(message = "出生日期错误", groups = {Registry.class})
    private Date birthDay;

    @Email(message = "输入的邮箱地址不符合规范", groups = {Registry.class})
    private String mail;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getBirthDay() {
        return birthDay;
    }

    public void setBirthDay(Date birthDay) {
        this.birthDay = birthDay;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public interface Registry{};

    public interface Login{};

}
